﻿Imports System.Data.OleDb


Public Class AddHotel
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_Submit_Click(sender As Object, e As EventArgs) Handles btn_Submit.Click

        'Make this more robust - if user uploads a gif or anything else
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"

        If f_Picture.HasFile Then
            Dim picLocationOnHardDiskServer = Request.MapPath("Pictures") & "/" & newFileName
            f_Picture.SaveAs(picLocationOnHardDiskServer)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("TravelConnectionString").ConnectionString)
        Dim SqlString As String = "INSERT INTO Hotels(HotelName, Stars, Location, Description, HotelUrl, Pictures) VALUES (@f1, @f2, @f3, @f4, @f5, F6)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_HotelName.Text)
        cmd.Parameters.AddWithValue("@f2", rbl_Stars.SelectedValue)
        cmd.Parameters.AddWithValue("@f3", tb_Location.Text)
        cmd.Parameters.AddWithValue("@f4", tb_Description.Text)
        cmd.Parameters.AddWithValue("@f5", tb_HotelUrl.Text)
        cmd.Parameters.AddWithValue("@f6", "Pictures/" & newFileName)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("Confirmation.aspx")

    End Sub
End Class